﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DTO;
namespace BUS
{
    public class KhachHangBUS
    {
        public const int  ChuaDuTuoi = 0;
        public const int thatBai = 1;
        public const int TrungCMND_PassPost = 2;
        public const int ThanhCong = 3;
        public static int ThemKhachHang(KhachHangDTO _khachHang)
        {
            List<QuyDinhDTO> DSQD = QuyDinhBUS.LayDSQuyDinh(-1, "Độ tuổi tối thiểu");
            int year = DateTime.Now.Year;
            int _yearKhachHang = _khachHang.NgaySinh.Year;
            if (year - _yearKhachHang < DSQD[0].MoTa)
                return ChuaDuTuoi;
            if (LayDSKhachHang() != null)
            {
                if (LayDSKhachHang(-1,null, _khachHang.Cmnd_Passport).Count > 0)
                    return TrungCMND_PassPost;
            }
            if (!KhachHangDAO.ThemKhachHang(_khachHang))
                return thatBai;
            return ThanhCong;
        }
        public static int SuaThongTinKhachHang(KhachHangDTO _khachHang)
        {
            int year = DateTime.Now.Year;
            int _yearKhachHang = _khachHang.NgaySinh.Year;
            if (year - _yearKhachHang < 18)
                return ChuaDuTuoi;
            if (LayDSKhachHang() != null)
            {
                if (LayDSKhachHang(-1, null, _khachHang.Cmnd_Passport).Count > 0)
                    return TrungCMND_PassPost;
            }
            if(!KhachHangDAO.SuaThongTinKhachHang(_khachHang))
                return thatBai;
            return ThanhCong;
        }
        public static List<KhachHangDTO> LayDSKhachHang(int maKhachHang = -1, string hoTen = null, string cmnd_Passport = null)
        {
            return KhachHangDAO.LayDSKhachHang(maKhachHang, hoTen, cmnd_Passport);
        }
       
    }
}
